// import COS from 'cos-js-sdk-v5';
// SECRETID 和 SECRETKEY请登录 https://console.cloud.tencent.com/cam/capi 进行查看和管理
// const cos = new COS({
//   SecretId: 'AKIDSjkUxB8tPfdKlwqTpwlJabLo0wc190bv',
//   SecretKey: '4sRjjSu62h6HBpCJ9iz0mHVS8YhaDZeS'
// })
var CosAuth = require('./cos-auth')



export function uploadFile(file, {
  success = (obj) => { },
  error = (obj) => { }
}) {
  // 请求用到的参数
  var prefix = 'http://' + 'gx-1258001656' + '.cos.' + 'ap-guangzhou' + '.myqcloud.com/';

  const Authorization = CosAuth({
    SecretId: 'AKIDSjkUxB8tPfdKlwqTpwlJabLo0wc190bv',
    SecretKey: '4sRjjSu62h6HBpCJ9iz0mHVS8YhaDZeS',
    Method: 'POST',
    Pathname: `/`,
  })

  wx.uploadFile({
    url: prefix,
    name: 'file',
    filePath: file.path,
    formData: {
      'key': `shipu/mini_program/${file.name || Date.now()}.jpg`,
      'success_action_status': 200,
      'Signature': Authorization,
    },
    data: {
      file
    },
    success: function (res) {
      // console.log(res, '成功');
      success(res?.header)

    },
    fail: function (res) {
      // console.log('失败', res)
      error(res)
    }
  });

}